package com.bdqn.mapper;

import com.bdqn.pojo.Menu;
import com.bdqn.pojo.Role;
import com.bdqn.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface RoleMapper {
    /**
     * 查询所有的角色信息
     */
    @Select("select * from sys_role ")
    List<Role> selectAll();

    /**
     * 根据姓名模糊查询所有的角色信息
     */
    List<Role> selectByName(String name);

    /**
     * 添加角色
     */
    @Insert("INSERT INTO sys_role (role_name, role_code,role_sort,status,remark) VALUES (#{roleName},#{roleCode},#{roleSort},#{status},#{remark})")
    int add(Role role);

    /**
     * 批量角色对应的菜单权限
     */
    int addRoleMenu(@Param("rid") int rid,@Param("pids") List<Integer> pids,@Param("cids")  List<Integer> cids);


    /**
     * 查询用户拥有的角色
     */
    List<Role> selectByUid(int uid);

    @Delete("delete from sys_role_menu where role_id=#{rid}")
    int deleteById(int rid);

    @Select("select role_id from sys_role_user  where user_id=#{uid}")
    List<Integer> selectRids(int rid);

    @Select("select * from sys_role where role_id=#{roleId}")
    Role selectById(int id);

    @Update("update sys_role set role_name=#{name},role_code=#{descn},role_code=#{descn},role_code=#{descn} where role_id=#{id}")
    int updateRole(Role role);

    @Delete("delete from sys_role where id=#{id}")
    int deleteRole(int id);

    @Select("select menu_id from sys_role_menu mr inner join sys_menu m on mr.menu_id=m.menu_id where role_id=#{rid} and parent_ids is not null")
    List<Integer> getMidsMenus(int rid);


    int addRoleMenus(@Param("rid") int rid,@Param("mids") List<Integer> mids);
}
